package sqlengine.database.impl;

import java.io.Serializable;
import java.util.Map;


public class Record implements Serializable {
	private static final long serialVersionUID = 1L;
	private Map<String,String> record;
	int recordID;
	
	public Map<String, String> getRecord() {
		return record;
	}
	
	//set new Record according to record and schema
	public int setRecord(Map<String, String> record, Map<String,Integer> schema) {
		//traverse record map
		for(Map.Entry<String, String> entry : record.entrySet()){
			//record map contains key which included in schema
			if(schema.containsKey(entry.getKey())){
				//record map's value exceeds schema max length
				if(entry.getValue().length() > schema.get(entry.getKey())){
					return 2;
				}
			//if record map contains key which not included in schema
			}else{
				return 1;
			}			
		}
		//record is legal
		this.record = record;		
		return 0;
	}
	
	public String getKey(String columnName){
		return record.get(columnName);
	}

	public int getRecordID() {
		return recordID;
	}
	public void setRecordID(int recordID) {
		this.recordID = recordID;
	}
}
